import scrapy
import json
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.exceptions import NotConfigured
from scrapy.pipelines.images import ImagesPipeline

from doubanbook.mylib.mypymysql import mypymysql

from scrapy.utils.project import get_project_settings

images_store = get_project_settings().get('IMAGES_STORE')


class cctvImagePipeline(ImagesPipeline):

    def get_media_requests(self, item, info):
        # name = item['album_order_id']
        # sleep(0.1)
        name = item['shop']
        # yield scrapy.Request(url=item['imagelink'], meta={'name': name})
        yield scrapy.Request(url='http:' + item['img'], meta={'name': name})

        # 第三个运行函数,判断有没有保存成功 ,我该写了没有保存成功者保存在本地文件中,以后进行抓取
    # def item_completed(self, results, item, info):
    #     super().item_completed()
    # 重命名，若不重写这函数，图片名为哈希，就是一串乱七八糟的名字
    # def file_path(self, request, response=None, info=None):
    #     super().file_path()